<!DOCTYPE html>
<html lang="zh">
<meta charset="utf-8">
<head>
    <#include "${request.contextPath}/common/head.ftl"/>
</head>
<body class="gray-bg">
    <div class="wrapper white-bg">
        <div class="row">
            <div id="uploadDIv"></div>
        </div>
    </div>
</body>

    <#include "${request.contextPath}/common/footer.ftl"/>

    <link rel="stylesheet" href="${ctx}/static/js/plugins/upload/css/zyUpload.css" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/static/js/plugins/upload/css/webuploader.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/static/js/plugins/upload/css/diyUpload.css"/>
    <script type="text/javascript" src="${ctx}/static/js/plugins/upload/js/webuploader.html5only.min.js"></script>
    <script type="text/javascript" src="${ctx}/static/js/plugins/upload/js/diyUpload.js"></script>
    <script src="${ctx}/static/js/tookeen.js"></script>
    <script type="text/javascript">


        var lock=false;

        var imageUrlCache;

        var doSubmit = function (paramCallback) {
            var index = parent.layer.getFrameIndex(window.name);
            var callback = share.remove(index);
            if (callback && typeof(callback) === "function") {
                if(imageUrlCache){
                    localStorage.imageUrl = imageUrlCache;
                }
                callback();
            }else if(paramCallback && typeof(paramCallback) === "function"){
                if(imageUrlCache){
                    localStorage.imageUrl = imageUrlCache;
                }
                paramCallback();
            }
            if(lock){
                parent.layer.msg('上传完成', {icon: 1});
            }
            parent.layer.close(index);
            return false;
        };

        $(document).ready(function () {

            //上传照片
            $('#uploadDIv').diyUpload({
                url:"${ctx}/fileUpload/uploadImage",
                success:function( data ) {
                    lock= true;

                    //使用当前页面的变量当做缓冲区，避免用户上传了图片，但是没有点击确定导致下一次打开页面，点击确定，把之前上传了但是未确定的url一起放入了输入框
                    if(imageUrlCache){
                        imageUrlCache += ","+data.data;
                    }else{
                        imageUrlCache = data.data;
                    }

                    //这种方式有bug
//                    if(localStorage.imageUrl){
//                        localStorage.imageUrl += ","+data.data;
//                    }else{
//                        localStorage.imageUrl= data.data;
//                    }
                },
                error:function( err ) {
                    console.info( err );
                },
                buttonText : '选择图片',
                chunked:false, //文件大了之后是否分片上传  false 不分片
                // 分片大小
                chunkSize:1024 * 1024*2,
                //最大上传的文件数量, 总文件大小,单个文件大小(单位字节);
                fileNumLimit:5,
                fileSizeLimit:50 * 1024*1024,
                fileSingleSizeLimit:50 * 1024*1024
                //accept: {}
            });
        });
    </script>


</html>


